package com.zhanggm.springcloud.jpa.service.impl;

import com.zhanggm.springcloud.jpa.repository.TbDocSkillRepository;
import com.zhanggm.springcloud.jpa.service.TbDocSkillService;
import com.zhanggm.springcloud.jpa.entity.TbDocSkill;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
@author Zhanggm
*/
@Service
public class TbDocSkillServiceImpl implements TbDocSkillService {

	@Resource
	private TbDocSkillRepository docSkillRepository;

	@Override
	public List<TbDocSkill> getListByDockerId(Integer doctorId) {
		return docSkillRepository.findByDocId(doctorId);
	}

	@Override
	public List<Integer> getSkillIdListByDockerId(Integer doctorId) {
		return docSkillRepository.findSkillIdListByDocId(doctorId);
	}

	@Override
	public List<TbDocSkill> getListBySkillId(Integer skillId) {
		return docSkillRepository.findBySkillId(skillId);
	}

	@Override
	public List<Integer> getDoctorIdListBySkillId(Integer skillId) {
        List<TbDocSkill> bySkillId = docSkillRepository.findBySkillId(skillId);
        return bySkillId.stream().map(r->r.getDocId()).collect(Collectors.toList());
	}

    @Override
    public int delByDockerId(Integer doctorId) {
        return docSkillRepository.deleteByDocId(doctorId);
    }

    @Override
    public int save(List<TbDocSkill> docSkills) {
        return docSkillRepository.saveAll(docSkills).size();
    }
}
